package com.study.springcache.service.impl;

import com.study.springcache.model.TestModel;
import com.study.springcache.service.CacheService;
import jakarta.annotation.PostConstruct;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.yaml.snakeyaml.tokens.AliasToken;

import java.time.LocalDateTime;

/**
 * @Description:
 * @Author: 刘超
 * @Date: 2023-03-01 9:58
 */
@Service
public class CacheServiceImpl implements CacheService {

    @Override
    @Cacheable(cacheManager = "caffeineCacheManager", value = "test", key = "#id", condition = "#id<3", unless = "#result==null")
    public TestModel getData(int id) {
        System.out.println("造数据..." + id + " " + LocalDateTime.now());
        if (0 == id) {
            return null;
        }
        TestModel testModel = new TestModel();
        testModel.setMsg("cacheData" + id);
        return testModel;
    }



}
